package num189;

import java.util.Arrays;

/**
 * @author : DuJiabao
 * @Project : sword-finger-offer
 * @Time : 2021/5/8 18:12
 * @Desc :
 */
public class Solution {
  public void rotate(int[] nums, int k) {
    if (k <= 0) return;
    int length = nums.length;
    k %= length;
    int[] temp = new int[k];
    for (int i = length - k, j = 0; i < length; i++, j++) {
      temp[j] = nums[i];
    }
    for (int i = length - k - 1; i >= 0; i--) {
      nums[i + k] = nums[i];
    }
    for (int i = 0; i < temp.length; i++) {
      nums[i] = temp[i];
    }
  }

  public static void main(String[] args) {
    int[] nums = {1, 2, 3, 4, 5, 6, 7};
    new Solution().rotate(nums, 2);
    System.out.println(Arrays.toString(nums));
  }
}
